package com.itcast.dao;

import com.itcast.pojo.po.User;
import com.itcast.pojo.vo.AddUser;
import com.itcast.pojo.vo.UpdateUser;
import org.apache.ibatis.annotations.*;



import java.util.List;


public interface BookDao {
    //查询全部
    public List<User> selectUser();


    //添加

    //逻辑1添加用户

    @Insert("insert  into  t_user values (null,#{username},#{password},#{remark},#{email},null,null)")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    public Integer insertUser(AddUser addUser);

    //逻辑2添加用户的权限
    @Insert("insert  into t_user_role(user_id, role_id) values (#{userid},#{roleid})")
    public abstract Integer insertrole(@Param("userid") Integer a, @Param("roleid") Integer ss);

    //修改
    //逻辑1根据名字查询用户是否存在
    @Select("select id, username, password, remark, email, createTime, updateTime  from t_user  where id=#{id}")
    public User selectname(UpdateUser updateUser);

    //逻辑2先删除角色表中id
    @Delete("delete  from t_user where id= #{id}")
    public Integer delete(Integer id);

    //逻辑3添加角色表中数据,由于上面代码写死造重复代码,可优化
    @Insert("insert  into t_user_role(user_id, role_id) values (#{user_id},#{role_id});")
    public Integer insertrole1(@Param("user_id") Integer user_id, @Param("role_id") Integer role_id);

    //逻辑4更改用户修改的数据
    @Update("update t_user set username=#{username},password=#{password},email=#{email} where id = #{id}")
    public Integer updata(UpdateUser updateUser);

    //删除功能
    //逻辑1先删除角色表方法
    //逻辑2在删除角色
    @Delete("delete  from t_user_role where user_id= #{id}")
    public Integer tuserrole(Integer id);

    @Delete("delete from t_user where id=#{id}  ")
    public Integer deleteUser(Integer id);
}
